#include "stdafx.h"
#include "WarningReport.h"
#include "Util.h"

const TCHAR* c_AryMusic[]     = {
    _T("config\\sound\\whisper.wav"),
    _T("config\\sound\\bagful.wav"),
    _T("config\\sound\\bypk.wav"),
    _T("config\\sound\\offline.wav"),
    _T("config\\sound\\dead.wav"),
    _T("config\\sound\\botnone.wav"),
    _T("config\\sound\\block.wav"),
    _T("config\\sound\\noProjectile.wav"),
    _T("config\\sound\\Mage.txt"),
    _T("config\\sound\\Warlock.txt"),
    _T("config\\sound\\unk.txt"),
    _T("config\\sound\\Druid.txt")
};

CWarning::CWarning()
{
    m_bIsBeeping = false;
    m_hBeep = ::CreateThread(NULL, 0, CWarning::BeepThread, 0, CREATE_SUSPENDED, 0);
}

CWarning::~CWarning()
{
    ::CloseHandle(m_hBeep);
}

DWORD WINAPI CWarning::BeepThread(LPVOID lParam)
{
	while(1)
	{
		::Beep(2200,500);
	}
	return 0;
}

void CWarning::Init(E_PLAY_TYPE etype)
{
    m_type = etype; 
}

void CWarning::Play(DWORD index)
{
    if (m_type == E_WAV)
        CUtil::PlayMusic(c_AryMusic[index]);
    else /*if (m_type == E_BEEP)*/
    {
        if (m_bIsBeeping)
        {
            return;
        }
        else
        {
            m_bIsBeeping = true;
	        ResumeThread(m_hBeep);
        }
    }
}

void CWarning::Stop()
{
    if (m_type == E_WAV)
        CUtil::StopMusic();
    else /*if (m_type == E_BEEP)*/
    {
        if (!m_bIsBeeping) return;
        m_bIsBeeping = false;
        SuspendThread(m_hBeep);
    }
}